package Offer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 数据流中的中位数
 * @author 是阿秋啊
 * @date 2022/08/15 22:12
 **/
public class Num41 {
    /** initialize your data structure here. */
    int midNumber = 0;
    List<Integer> list = new ArrayList<>();

    public void addNum(int num) {
        list.add(num);
        Collections.sort(list);
    }

    public double findMedian() {
        int size = list.size();
        if(size % 2 == 1){
            return (double)(1.0 * list.get(size / 2));
        }else{
            return (double)(1.0 * (list.get(size / 2) + list.get(size / 2 - 1)) / 2);
        }
    }
}